# _*_ encoding:utf-8 _*_

from datetime import datetime

from django.db import models
from django.contrib.auth.models import AbstractUser
from django.utils.translation import gettext_lazy as _
from django.core.validators import RegexValidator

# Create your models here.


class UserProfile(AbstractUser):
    nick_name = models.CharField(max_length=50, verbose_name='昵称', default='')
    birthday = models.DateField(verbose_name=u'生日', null=True, blank=True)

    # django 3.0 later
    class Gender(models.TextChoices):
        male = 'male', u'男'
        female = 'female', u'女'

    gender = models.CharField(
        max_length=6, choices=Gender.choices, default=Gender.male, verbose_name=u'性别')

    address = models.CharField(max_length=100, default='', verbose_name=u'地址')

    telNumValidator = RegexValidator(
        r'1[35678]\d{9}$', _('is not telephone number.'))
    mobile = models.CharField(max_length=11, null=True, blank=True, validators=[
                              telNumValidator], verbose_name=u'手机号码')
    image = models.ImageField(upload_to='image/%Y/%m',
                              default='image/default.png', max_length=100)

    class Meta:
        verbose_name = u'用户信息'
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.username


class EmailVarifyRecord(models.Model):
    code = models.CharField(max_length=10, verbose_name=u'验证码')
    email = models.EmailField(max_length=50, verbose_name=u'邮箱')
    send_type = models.CharField(max_length=50, choices=[(
        'register', u'注册'), ('forget', u'找回密码')], verbose_name=u'发送类型')
    send_time = models.DateTimeField(
        default=datetime.now, verbose_name=u'发送时间')

    class Meta:
        verbose_name = u'邮箱验证码'
        verbose_name_plural = verbose_name


class Banner(models.Model):
    title = models.CharField(max_length=100, verbose_name=u'标题')
    image = models.ImageField(
        max_length=100, upload_to='banner/%Y%m', verbose_name=u'轮播图片')
    url = models.URLField(max_length=200, verbose_name=u'访问地址')
    index = models.IntegerField(default=0, verbose_name=u'顺序')
    add_time = models.DateTimeField(default=datetime.now, verbose_name=u'添加时间')

    class Meta:
        verbose_name = u'轮播图'
        verbose_name_plural = verbose_name
